package com.yqy.trans;

import com.yqy.Employee;
import com.yqy.PaymentClassification;
import com.yqy.PayrollDatabase;
import com.yqy.Transaction;
import com.yqy.classification.HourlyClassification;
import com.yqy.classification.TimeCard;
import com.yqy.exception.NotHourlyClassificationException;

public class TimeCardTransaction implements Transaction {

    private int empId;
    private String date;
    private double hours;

    public TimeCardTransaction(int empId, String date, double hours) {
        this.empId = empId;
        this.date = date;
        this.hours = hours;
    }
    
    @Override
    public void execute() {
        // 根据雇员编号取雇员对象
        Employee e = PayrollDatabase.getEmployee(empId);        
        // 取计算工资方法
        PaymentClassification pc = e.getPaymentClassification();
        if (pc instanceof HourlyClassification) {  
            HourlyClassification hc = (HourlyClassification) pc;
            // 添加时间卡
            TimeCard tc = new TimeCard(date, hours);
            hc.addTimeCard(tc);
        } else {
            throw new NotHourlyClassificationException();
        }
        
    }

}
